﻿/*
 * Erstellt mit SharpDevelop.
 * Benutzer: Kai Patrick
 * Datum: 18.03.2008
 * Zeit: 20:15
 * 
 * Sie können diese Vorlage unter Extras > Optionen > Codeerstellung > Standardheader ändern.
 */

using System;
using System.Windows.Forms;
using System.Collections.Generic;

namespace Gamadus.Designer
{
	public class ActionSetMgr : Gamadus.Core.SingletonManager<ActionSetMgr>
	{
		public List<ActionSet> ActionSets = new List<ActionSet>();
		public void Init()
		{
			ActionSet aset;
			Dictionary<string, Type> paramType;
			aset = new ActionSet("control");
				aset.Groups.Add("Code");
					paramType = new Dictionary<string, Type>();
					paramType.Add("Code",typeof(ActionParamString));
					aset.Actions.Add(new ActionPrototype("Execute Code", "Code","executecode", "Execute a piece of code", paramType));
					
					//for testing:
					paramType = new Dictionary<string, Type>();
					paramType.Add("Code",typeof(ActionParamString));
					aset.Actions.Add(new ActionPrototype("Other Action", "Code","", "Do {0}", paramType));
			ActionSets.Add(aset);
		}
		
		public ActionPrototype FindPrototypeByName(string name)
		{
			foreach(ActionSet aset in ActionSets)
			{
				foreach(ActionPrototype action in aset.Actions)
				{
					if(action.Name == name)
						return action;
				}
			}
			return null;
		}
	}
		
	/// <summary>
	/// Description of ActionSet.
	/// </summary>
	public class ActionSet
	{
		public List<string> Groups = new List<string>();
		public string Name;
		public List<ActionPrototype> Actions = new List<ActionPrototype>();
		public ActionSet(string name)
		{
			Name = name;
		}
	}
	
	public class ActionPrototype
	{
		public string Name;
		public string Group;
		public string DescriptionPrototype;
		public Dictionary<string,Type> ParamTypes;
		public string ImageKey;
		
		public ActionPrototype(string name, string group, string imageKey, string description, Dictionary<string,Type> paramTypes)
		{
			Name = name;
			Group = group;
			DescriptionPrototype = description;
			ImageKey = imageKey;
			foreach(KeyValuePair<string, Type> type in paramTypes)
			{
				if(!type.Value.IsSubclassOf(typeof(ActionParam)))
					throw new ArgumentException("One ore more Types in paramTypes list aren't children of ActionParam");
			}
			ParamTypes = paramTypes;
		}
		
		public void ShowEditForm(Action action)
		{
			if(this.Name == "Execute Code")
			{
				CodeEditor editor = new CodeEditor(ResourceMgr.Instance.MainForm,action);
				ResourceMgr.Instance.editWindows.Add(editor);
				editor.Show();
			}
			else
			{
				//TODO: add action parameter controls to form
				Form form = new Form();
				form.MinimizeBox = false;
				form.MaximizeBox = false;
				form.ShowInTaskbar = false;
				form.ShowIcon = false;
				form.ShowDialog();
			}
		}
	}
}
